<?php
/**
 * 违例处理句柄
 *
 * @author ananda
 */
class Exception_Handler
{
    /**
     * 安静模式处理未捕获违例
     * @param Exception $e
     */
    public static function uncaughtQuiet(Exception $e)
    {
        echo $e;
    }

    /**
     * 对未捕获的违例进行处理
     * 暂时不考虑级虽问题
     * @param Exception $e
     */
    public static function uncaughtException(Exception $e)
    {
        //$message  = $e->getMessage();
        //$code     = $e->getCode();
        $file     = $e->getFile();
        $line     = $e->getLine();
        //$severity = 0;

        if (isset($_SERVER['REQUEST_URI'])) {
            echo "<p><strong>Uncaught Exception</strong><br />File: $file<br />Line: $line</p>",
                 '<pre>', $e, '</pre>';
        } else {
            echo "\nFile: $file\nLine: $line\n",
                 $e, "\n";
        }
    }

    /**
     * 错误转伟例函数
     * @param <integer> $errno
     * @param <string> $errstr
     * @param <string> $errfile
     * @param <integer> $errline
     * @return <boolean>
     */
    public static function errorHandler($errno, $errstr, $errfile, $errline, $errcontext = array())
    {
        if (intval(ini_get('log_errors'))) {
            error_log("PHP Error[$errno]: $errstr in $errfile on line $errline", 0);
        }

        $test = intval(ini_get('error_reporting')) & $errno;
        if (!$test) {
            return false;
        }

        throw new Exception_PhpError($errstr, 0, $errno, $errfile, $errline);
        return true;
    }

}
